<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Array Opcodes</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="MathTop.html" title="Mathematical Operations" />
    <link rel="prev" href="linearalgebraopcodes.html" title="Linear Algebra Opcodes" />
    <link rel="next" href="PitchTop.html" title="Pitch Converters" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Array Opcodes</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="linearalgebraopcodes.html">Prev</a> </td>
          <th width="60%" align="center">Mathematical Operations</th>
          <td width="20%" align="right"> <a accesskey="n" href="PitchTop.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="arrayOpcodes"></a>
      <div class="titlepage"></div>
      <a id="Indexarray" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">Array Opcodes</span>
        </h2>
        <p>Array Opcodes</p>
      </div>
      <div class="refsect1">
        <a id="idp83655040"></a>
        <h2>Variable Name</h2>
        <p>
      An array must be created (via <a class="link" href="init.html" title="init"><em class="citetitle">init</em></a>
      or <a class="link" href="fillarray.html" title="fillarray"><em class="citetitle">fillarray</em></a>) as
      kMyName <span class="strong"><strong>plus</strong></span> ending brackets. The
      brackets determine
      the dimensions of the array. So,
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[] <span class="opc">init</span> 10</pre>
        </div>
        <p>
      creates a one-dimensional array of length 10, whereas
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[][] <span class="opc">init</span> 10, 10</pre>
        </div>
        <p>
      creates a two-dimensional array with 10 rows and 10 columns.
    </p>
        <p>
      After the initalization of the array, referring to the array as a whole is
      done <span class="strong"><strong>without</strong></span> any brackets. Brackets are
      only used if an element is indexed:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[]   <span class="opc">init</span> 10             <span class="comment">;with brackets because of initialization</span>
kLen     <span class="op">=</span> lenarray(kArr)    <span class="comment">;without brackets</span>
kFirstEl <span class="op">=</span> kArr[0]           <span class="comment">;indexing with brackets</span></pre>
        </div>
        <p>
    </p>
        <p>
      The same syntax is used for a simple copy via the '=' operator:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr1[] <span class="opc">fillarray</span> 1, 2, 3, 4, 5
kArr2[] <span class="op">=</span> kArr1              <span class="comment">;creates kArr2 as copy of kArr1</span></pre>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83672624"></a>
        <h2>k-rate</h2>
        <p>
      Note that most array operations are currently k-rate only. So like any
      other k-rate opcode, an operation on arrays will be automatically repeated
      every k-cycle. For instance, this code will repeat re-writing the array
      with different random values every k-cycle, as long as the instrument runs:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[] <span class="opc">init</span> 10
kIndx  <span class="op">=</span> 0
<span class="octrl">until</span> kIndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr) <span class="octrl">do</span>
  kArr[kIndx] <span class="opc">rnd31</span> 10, 0
  kIndx <span class="op">+=</span> 1
<span class="octrl">od</span></pre>
        </div>
        <p>
    </p>
        <p>
      If you want to avoid this, you must organize it in one of the usual ways,
      for instance by using a trigger:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[] <span class="opc">init</span> 10
kTrig <span class="opc">metro</span> 1
<span class="octrl">if</span> kTrig <span class="op">==</span> 1 <span class="octrl">then</span> <span class="comment">;do the following once a second</span>
  kIndx  <span class="op">=</span> 0
  <span class="octrl">until</span> kIndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr) <span class="octrl">do</span>
    kArr[kIndx] <span class="opc">rnd31</span> 10, 0
    kIndx <span class="op">+=</span> 1
  <span class="octrl">od</span>
<span class="octrl">endif</span></pre>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83692944"></a>
        <h2>Creation/Initialization</h2>
        <p>
      The usual way to create an array is with init:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[]   <span class="opc">init</span> 10     <span class="comment">;creates one-dimensional array with length 10</span>
kArr[][] <span class="opc">init</span> 10, 10 <span class="comment">;creates two-dimensional array</span></pre>
        </div>
        <p>
    </p>
        <p>
      A one-dimensional array can also be created and filled with distinct values
      by the opcode <span class="emphasis"><em>fillarray</em></span>. This line creates a vector
      with length 4 and puts in the numbers [1, 2, 3, 4]:
    </p>
        <div class="informalexample">
          <pre class="programlisting">
kArr[] <span class="opc">fillarray</span> 1, 2, 3, 4</pre>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp83700768"></a>
        <h2>Length</h2>
        <p>
      The function <span class="emphasis"><em>lenarray(kArr)</em></span> reports the length of an
      array. See example for function
      <a class="link" href="lenarray.html" title="lenarray"><em class="citetitle">lenarray</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83703616"></a>
        <h2>Copy Arrays to/from Tables</h2>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
<span class="opc">copyf2array</span> kArr, kfn</pre>
        </div>
        <p>
      copies data from an ftable to a vector.
    </p>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
<span class="opc">copya2ftab</span> kArr, kfn</pre>
        </div>
        <p>
      copies data from a vector to an function table.
    </p>
        <p>
      See examples for opcodes
      <a class="link" href="copyf2array.html" title="copyf2array"><em class="citetitle">copyf2array</em></a> and
      <a class="link" href="copya2ftab.html" title="copya2ftab"><em class="citetitle">copya2ftab</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83711408"></a>
        <h2>Array Operations: Math</h2>
        <div class="refsect2">
          <a id="idp83712080"></a>
          <h3>+, -, *, / on a Number</h3>
          <p>
        If the four basic math operators are used between an array and a scalar 
        (number), the operation is applied to each element. The safest way to do
        this is to store the result in a new array:
        </p>
          <div class="informalexample">
            <pre class="programlisting">
kArr1[] <span class="opc">fillarray</span> 1, 2, 3
kArr2[] <span class="op">=</span> kArr1 <span class="op">+</span> 10    <span class="comment">;(kArr2 is now [11, 12, 13])</span></pre>
          </div>
          <p>
        Here is an example of array/scalar operations. It uses the file
        <a class="ulink" href="examples/array_scalar_math.csd" target="_top"><em class="citetitle">array_scalar_math.csd</em></a>.
        </p>
          <div class="example">
            <a id="idp83717856"></a>
            <p class="title">
              <strong>Example 3. Example of array operations</strong>
            </p>
            <div class="example-contents">
              <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-n -m128
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>


  <span class="oblock">instr</span> 1

<span class="comment">;create array and fill with numbers 1..10</span>
kArr1[] <span class="opc">fillarray</span> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nInitial content<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr1) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr1[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;add 10</span>
kArr2[] <span class="op">=</span>       kArr1 <span class="op">+</span> 10

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nAfter adding 10<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr2) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr2[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;subtract 5</span>
kArr3[] <span class="op">=</span>       kArr2 <span class="op">-</span> 5

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nAfter subtracting 5<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr3) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr3[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;multiply by -1.5</span>
kArr4[] <span class="op">=</span>       kArr3 <span class="op">*</span> <span class="op">-</span>1.5

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nAfter multiplying by <span class="op">-</span>1.5<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr4) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr4[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;divide by -3/2</span>
kArr5[] <span class="op">=</span>       kArr4 <span class="op">/</span> <span class="op">-</span>(3<span class="op">/</span>2)

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nAfter dividing by <span class="op">-</span>3<span class="op">/</span>2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr5) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr5[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;turnoff</span>
        <span class="opc">turnoff</span>
  <span class="oblock">endin</span>
  

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 .1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
            </div>
          </div>
          <p><br class="example-break" />
      </p>
        </div>
        <div class="refsect2">
          <a id="idp83719776"></a>
          <h3>+, -, *, / on a Second Array</h3>
          <p>
        If the four basic math operators are used between two arrays, the
        operation is applied element by element. The result can be
        straightforward stored in a new array:
        </p>
          <div class="informalexample">
            <pre class="programlisting">
kArr1[] <span class="opc">fillarray</span> 1, 2, 3
kArr2[] <span class="opc">fillarray</span> 10, 20, 30
kArr3[] <span class="op">=</span> kArr1 <span class="op">+</span> kArr2    <span class="comment">;(kArr3 is now [11, 22, 33])</span></pre>
          </div>
          <p>
        Here is an example of array operations. It uses the file
        <a class="ulink" href="examples/array_array_math.csd" target="_top"><em class="citetitle">array_array_math.csd</em></a>.
        </p>
          <div class="example">
            <a id="idp83726160"></a>
            <p class="title">
              <strong>Example 4. Example of array operations</strong>
            </p>
            <div class="example-contents">
              <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-n -m128
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

  <span class="oblock">instr</span> 1

<span class="comment">;create array and fill with numbers 1..10 resp .1..1</span>
kArr1[] <span class="opc">fillarray</span> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
kArr2[] <span class="opc">fillarray</span> 1, 2, 3, 5, 8, 13, 21, 34, 55, 89

<span class="comment">;print contents</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr1) do
        <span class="opc">printf</span>  "kArr1[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr1[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr2) do
        <span class="opc">printf</span>  "kArr2[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr2[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;add arrays</span>
kArr3[] <span class="op">=</span>       kArr1 <span class="op">+</span> kArr2

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1 <span class="op">+</span> kArr2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr3) do
        <span class="opc">printf</span>  "kArr3[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr3[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;subtract arrays</span>
kArr4[] <span class="op">=</span>       kArr1 <span class="op">-</span> kArr2

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1 <span class="op">-</span> kArr2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr4) do
        <span class="opc">printf</span>  "kArr4[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr4[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;multiply arrays</span>
kArr5[] <span class="op">=</span>       kArr1 <span class="op">*</span> kArr2

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1 <span class="op">*</span> kArr2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr5) do
        <span class="opc">printf</span>  "kArr5[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr5[kndx]
kndx <span class="op">+</span><span class="op">=</span> 1
  od

<span class="comment">;divide arrays</span>
kArr6[] <span class="op">=</span>       kArr1 <span class="op">/</span> kArr2

<span class="comment">;print content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1 <span class="op">/</span> kArr2<span class="op">:</span>\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr6) do
        <span class="opc">printf</span>  "kArr5[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr6[kndx]
kndx <span class="op">+</span><span class="op">=</span> 1
  od

<span class="comment">;turnoff</span>
        <span class="opc">turnoff</span>
        
  <span class="oblock">endin</span>
  
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 .1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
            </div>
          </div>
          <p><br class="example-break" />
      </p>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp83728208"></a>
        <h2>Map a Function to an Array</h2>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArrRes <span class="opc">maparray</span> kArrSrc, "fun"</pre>
        </div>
        <p>
      maps the k-rate 1-arg function in the string to every element of the vector.
    </p>
        <p>
      Possible functions are for instance <span class="emphasis"><em>abs, ceil, exp, floor, frac,
      int, log, log10, round, sqrt</em></span>. This is a simple example:
      </p>
        <div class="informalexample">
          <pre class="programlisting">
kArrSrc[] <span class="opc">fillarray</span> 1, 2, 3, 4, 5
kArrRes[] <span class="opc">init</span>      5
kArrRes   <span class="opc">maparray</span>  kArrSrc, "sqrt"</pre>
        </div>
        <p>
      See example for opcode
      <a class="link" href="maparray.html" title="maparray"><em class="citetitle">maparray</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83736512"></a>
        <h2>Array Operations: min, max, sum, scale, slice</h2>
        <div class="refsect2">
          <a id="idp83737216"></a>
          <h3>Minimum and Maximum</h3>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  kMin [,kMinIndx] <span class="opc">minarray</span> kArr</pre>
          </div>
          <p>
        returns the smallest value in an array, and optionally its index.
      </p>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  kMax [,kMaxIndx] <span class="opc">maxarray</span> kArr</pre>
          </div>
          <p>
        returns the largest value in an array, and optionally its index.
        See examples for opcodes
        <a class="link" href="minarray.html" title="minarray"><em class="citetitle">minarray</em></a> and
        <a class="link" href="maxarray.html" title="maxarray"><em class="citetitle">maxarray</em></a>.
      </p>
        </div>
        <div class="refsect2">
          <a id="idp83744352"></a>
          <h3>Sum</h3>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  kSum <span class="opc">sumarray</span> kArr</pre>
          </div>
          <p>
        returns the sum of all values in kArr.
        See example for opcode
        <a class="link" href="sumarray.html" title="sumarray"><em class="citetitle">sumarray</em></a>.
      </p>
        </div>
        <div class="refsect2">
          <a id="idp83748368"></a>
          <h3>Scale</h3>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  <span class="opc">scalearray</span> kArr, kMin, kMax</pre>
          </div>
          <p>
        scales all values in kArr between kMin and kMax.
      </p>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  kArr[] <span class="opc">fillarray</span>  1, 3, 9, 5, 6
         <span class="opc">scalearray</span> kArr, 1, 3</pre>
          </div>
          <p>
        changes <span class="emphasis"><em>kArr</em></span> to [1, 1.5, 3, 2, 2.25].
        See example for opcode
        <a class="link" href="scalearray.html" title="scalearray"><em class="citetitle">scalearray</em></a>.
      </p>
        </div>
        <div class="refsect2">
          <a id="idp83755696"></a>
          <h3>Slice</h3>
          <p>
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  <span class="opc">slicearray</span> kArr, iStart, iEnd</pre>
          </div>
          <p>
        returns a slice of <span class="emphasis"><em>kArr</em></span> from index
        <span class="emphasis"><em>iStart</em></span> to index <span class="emphasis"><em>iEnd</em></span> (included).
      </p>
          <p>
        The array for receiving the slice must have been created in advance:
        </p>
          <div class="informalexample">
            <pre class="programlisting">
  kArr[]  <span class="opc">fillarray</span>  1, 2, 3, 4, 5, 6, 7, 8, 9
  kArr1[] <span class="opc">init</span>       5
  kArr2[] <span class="opc">init</span>       4
  kArr1   <span class="opc">slicearray</span> kArr, 0, 4        <span class="comment">;[1, 2, 3, 4, 5]</span>
  kArr2   <span class="opc">slicearray</span> kArr, 5, 8        <span class="comment">;[6, 7, 8, 9]</span></pre>
          </div>
          <p>
        See example for opcode
        <a class="link" href="slicearray.html" title="slicearray"><em class="citetitle">slicearray</em></a>.
      </p>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp83767616"></a>
        <h2>Arrays in UDOs</h2>
        <p>
      The dimension of an input array must be declared in two places:
      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
          as k[] or k[][] in the type input list
        </li>
            <li class="listitem">
          as kName[], kName[][] etc in the xin list.
        </li>
          </ul>
        </div>
        <p>
      For instance :
      </p>
        <div class="informalexample">
          <pre class="programlisting">
<span class="oblock">opcode</span> FirstEl, k, k[]
<span class="comment">;returns the first element of vector kArr</span>
kArr[] <span class="opc">xin</span>
       <span class="opc">xout</span>   kArr[0]
<span class="oblock">endop</span></pre>
        </div>
        <p>
      Here is an example of an array in an UDO. It uses the file
      <a class="ulink" href="examples/array_udo.csd" target="_top"><em class="citetitle">array_udo.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp83775328"></a>
          <p class="title">
            <strong>Example 5. Example of an array in an UDO</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-nm128
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

  <span class="oblock">opcode</span> FirstEl, k, k[]
  <span class="comment">;returns the first element of vector kArr</span>
kArr[] <span class="opc">xin</span>
<span class="opc">xout</span> kArr[0]
  <span class="oblock">endop</span>

  <span class="oblock">instr</span> 1 
kArr[] <span class="opc">fillarray</span> 6, 3, 9, 5, 1
kFirst FirstEl kArr
<span class="opc">printf</span> "kFirst <span class="op">=</span> <span class="op">%</span>d\n", 1, kFirst
<span class="opc">turnoff</span>
  <span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 .1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp83777248"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>This manual page has been written by Joachim Heintz.</td>
          </tr>
          <tr>
            <td>July 2013</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound 6.00</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="linearalgebraopcodes.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="MathTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="PitchTop.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Linear Algebra Opcodes </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Pitch Converters</td>
        </tr>
      </table>
    </div>
  </body>
</html>
